import { exec } from "child_process";
import * as fs from "fs";

export const promiseExec = (command: string) => new Promise((resolve, _) => exec(command, (_error, stdout, _stderr) => resolve(stdout)));
export const createFolders = async (folderNames: string[]) => {
  folderNames.forEach(folderName => {
    console.log(folderName);
    fs.mkdir(folderName,()=>{});
  });
};

export const generateRandomString = (length: number): string => {
  const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  let randomString = "";
  for (let i = 0; i < length; i++) {
    randomString += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return randomString;
};

export const currentTime = () => {
  const date = new Date();
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return `${year}${month < 10 ? "0" + month : month}${day < 10 ? "0" + day : day}`;
}

export const padWithZeros = (num:number) =>{
  let str = String(num);
  while (str.length < 3) {
    str = '0' + str;
  }
  return str;
}
